<?php

class album {
	function form($object, $config) {
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();
		
		global $db;
		
		$form = new form();
		
		// get all currency type
		$currency_type=$db->selectDropdown("currency","name");
		$format_type=$db->selectDropdown("album_format","name");
		$genre_type=$db->selectDropdown("album_genre","name");
		
		// 2010/07/13: immanuel192 add new function: sort
		$sort_by=array();
		$sort_by[0]="Oldest first";
		$sort_by[1]="Newest first";
		// end of sort
		
		
		if (!isset($object->id)) {
			$object->name = '';
			$object->body = '';
			$object->downloadable=0;
			$object->released=date("Y");
			$object->price_sheet_book=10;
			$object->price_soundtrack_disk=10;
			$object->price_vocal=10;
			$object->has_vocal=0;
			$object->has_sheet=0;
			$object->has_soundtrack=0;
			$object->album_type=0;
			$object->format=0;		 	 	 	 	 	 	 
			$object->publisher="";		 	 	 	 	 	 	 
			$object->rate=3;		 	 	 	 	 	 	 
			$object->length=0;		 	 	 	 	 	 	 
			$object->n0_disk=0;		 	 	 	 	 	 	 
			$object->genre=0;		 	 	 	 	 	 	 
			$object->price=0;
			$object->image_id=0;
			$object->is_new=0;
			$object->media_preview=0;
			$object->for_sale=0;
			$object->show_summary=1;
			$object->sort_by=0;
 	        
			foreach ($currency_type as $key=>$value) {
				$object->currency_type=$key;
				break;
			}
			foreach ($format_type as $key=>$value) {
				$object->format=$key;
				break;
			}
			foreach ($genre_type as $key=>$value) {
				$object->genre=$key;
				break;
			}
		} else {
			$form->meta('id',$object->id);
		}
		
		$form->register('name','Name',new textcontrol($object->name,50,false,200));
		$form->register('body','Info',new htmleditorcontrol($object->body));
		$form->register('image_id','Upload Picture', new ajax_select_file("image_id",$config->album_collection,$object->image_id,true));
		$form->register('released','Released Year',new textcontrol($object->released));
		
		$form->register('format',"Format",new dropdowncontrol($object->format,$format_type));		 	 	 	 	 	 	 
		$form->register('sort_by',"Sort items by",new dropdowncontrol($object->sort_by,$sort_by));
 	  
 	  $form->register('publisher','Publisher',new textcontrol($object->publisher));
    
    $form->register('n0_disk','Media Box Count',new textcontrol($object->n0_disk));
		$form->register('genre',"Genre",new dropdowncontrol($object->genre,$genre_type));
		
		// 4/1/2010: disable by contract
		/*
		//$form->register('price','Price',new textcontrol($object->price));
		$form->register('has_sheet','This album has Sheetbook',new checkboxcontrol($object->has_sheet));
		$form->register('price_sheet_book','Price of Sheet Book',new textcontrol($object->price_sheet_book));
		$form->register('has_vocal','This album has vocal disk',new checkboxcontrol($object->has_vocal));
		$form->register('price_vocal','Price of Vocal Disk',new textcontrol($object->price_vocal));
		$form->register('has_soundtrack','This album has SoundTrack disk',new checkboxcontrol($object->has_soundtrack));
		$form->register('price_soundtrack_disk','Price of Soundtrack Disk',new textcontrol($object->price_soundtrack_disk));
		//$form->register('currency_type','Currency type',new dropdowncontrol($object->currency_type, $currency_type));
		*/
		// 9/12/2009; immanuel192 add media player preview mode
		$media_preview = array(0=>'No Preview', 1=>'Audio Player', 2=>'Video Player');
		$form->register('media_preview','Media Player',new dropdowncontrol($object->media_preview, $media_preview));
		
		$form->register('length','Total Media Length', new mediatime_control($object->length));
    $form->register('rate','Rating (0-5)',new textcontrol($object->rate));	
		$form->register('downloadable','All music in this album can be downloadable',new checkboxcontrol($object->downloadable));
		$form->register('is_new','Show icon NEW',new checkboxcontrol($object->is_new));
		//$form->register('for_sale','This album is for sale',new checkboxcontrol($object->for_sale));
		$form->register('show_summary','Show summary information',new checkboxcontrol($object->show_summary));
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		return $form;
	}
	
	function update($values,$object) {
		$object->name = $values['name'];
		$object->body = $values['body'];
		
		if (isset($values['downloadable']))
			$object->downloadable = $values['downloadable'];
		else
		$object->downloadable=0;
		
		$object->released=$values['released'];
		
		$object->format=$values['format'];
		$object->publisher=$values['publisher'];
		$object->media_preview=$values['media_preview'];		 	 	 	 	 	 	 
		$object->rate=$values['rate'];
		$object->length=$values['length']; 	 	 
		$object->n0_disk=$values['n0_disk']; 	 
		$object->genre=$values['genre'];
		$object->sort_by=$values['sort_by'];
		
		if (isset($values['is_new']))
			$object->is_new= $values['is_new'];
		else
			$object->is_new=0;
      
		if (isset($values['for_sale']))
			$object->for_sale= $values['for_sale'];
		else
		$object->for_sale=0;
     
		if (isset($values['show_summary']))
			$object->show_summary= $values['show_summary'];
		else
		$object->show_summary=0;
		$object->image_id=$values['image_id'];
		
		// 4/1/2010: album sale function is not in contract: disable
		$object->for_sale=0;
		// Uncomment if you want to enable sale function
		/*$object->price=$values['price'];
		$object->price_sheet_book=$values['price_sheet_book'];
		$object->price_vocal=$values['price_vocal'];
		$object->price_soundtrack_disk=$values['price_soundtrack_disk'];
		$object->has_vocal=$values['has_vocal'];
		$object->has_soundtrack=$values['has_soundtrack'];
		$object->has_sheet=$values['has_sheet'];
		$object->currency_type=$values['currency_type'];*/
		return $object;
	}
}

?>
